<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/31 0031
 * Time: 下午 5:48
 */
namespace app\admin\model;
use think\Model;
class Shoppingcart extends Model
{
    /**
     * @return \think\model\relation\BelongsTo
     * 购物车关联商户信息
     */
    public  function shopinfo(){
         return self::belongsTo('shop','shop_id')->where('shop_status',1)->field('id,shop_name,shop_logo');
    }

    /**
     * @return \think\model\relation\BelongsTo
     * 购物车关联商品信息
     */
    public function goodsinfo(){
        return self::belongsTo('goods','goods_id')->field('id,goods_name,goods_price,goods_discount,goods_unit,goods_image');
    }

    /**
     * $userid  用户id
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 获取购物车的列表
     */
    static public function getshopcatlists($userid){
        return   collection(self::with('goodsinfo,shopinfo')->where('user_id',$userid)->order('addtime desc')->select())->toArray();
    }

}